<!DOCTYPE HTML>
<html>
<head>
    <title>Todo</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
    <script src="/editor/js/moveBall.js"></script>
</head>
<body  style="padding: 0;width: 100%;height: 100%">
<div id="outImg">
    <img id="imgId" src="" alt="" onclick="smallImg()">
</div>
<div style="padding-bottom:5px;">
    <span>用户昵称：</span><input class="mini-textbox" type="text" id="nickName"/>
    <span>用户id：</span><input class="mini-textbox" type="text" id="objectId"/>
    <span>用户电话：</span><input class="mini-textbox" type="text" id="mobilePhoneNumber"/>
    <span>部落id：</span><input class="mini-textbox" type="text" id="uid"/>
    <a class="mini-button" iconCls="icon-search" onclick="search()">查找</a>
</div>
<div style="width:99%;">
    <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <!--<a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>-->
                    <a class="mini-button" iconCls="icon-add" onclick="edit()">编辑</a>
                    <a class="mini-button" iconCls="icon-remove" onclick="redisRemove()">删除用户缓存</a>
                </td>
            </tr>
        </table>
    </div>
</div>
<div id="datagrid1" class="mini-datagrid" style="width:99%;height: 82%;"
     url="/getdata/usersInformation" idField="id" allowResize="true"
     sizeList="[20,30,50,100]" pageSize="30"
>
    <div property="columns">
        <div type="checkcolumn" ></div>
        <div field="objectId" width="80" headerAlign="center" allowSort="true" >objectId</div>
        <div field="nickName" width="80" headerAlign="center" allowSort="true" >用户昵称</div>
        <div field="gender"  width="70" align="center" headerAlign="center" renderer="onGenderRenderer" allowSort="true" >用户iocn</div>
        <div field="qrCode" width="70" align="center" headerAlign="center" renderer="onGenderRenderer" allowSort="true" >用户二维码</div>
        <div field="live_authority" renderer="onLiveRenderer" align="center" width="60" headerAlign="center" allowSort="true">直播权限</div>
        <div field="sex" width="40"  align="center" headerAlign="center" allowSort="true">性别</div>
        <div field="type" width="60"  align="center" headerAlign="center" allowSort="true" renderer="onTypeRenderer">用户等级</div>
        <div field="uid" align="center" width="60" headerAlign="center" allowSort="true">部落id</div>
        <div field="signature" align="left" width="100" headerAlign="center" allowSort="true">个性签名</div>
        <div field="authData" align="left" width="100" headerAlign="center" allowSort="true">authData</div>
        <div field="mobilePhoneNumber" align="center" headerAlign="center" width="70" allowSort="true" >电话号码</div>
        <div field="phoneRegVerify" align="center" headerAlign="center" width="70" allowSort="true" renderer="onPhoneRenderer">手机验证</div>
        <div field="status" align="center" headerAlign="center" width="70" allowSort="true"  renderer="onLoginRenderer">账号状态</div>
        <div field="userType" align="center" headerAlign="center" width="70" allowSort="true" >账号类型</div>
        <div field="address" align="center" headerAlign="center" width="70" allowSort="true" >账号地理位置</div>
        <div field="createAt" width="100" renderer="onBirthdayRenderer" align="center" headerAlign="center" allowSort="true">创建日期</div>
        <div field="updatedAt" width="100" renderer="onBirthdayRenderer" align="center" headerAlign="center" allowSort="true">更新日期</div>
        <div field="username" width="120" headerAlign="center" allowSort="true">用户名称</div>
    </div>
</div>
</body>
<script type="text/javascript">
    var flag = 1;
    mini.parse();
    var grid = mini.get("datagrid1");
    grid.load();
    grid.on("drawcell", function (e) {
         var  value = e.value;
            column = e.column;
        //将性别文本替换成图片
        if (column.field == "gender") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImg()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
        if (column.field == "qrCode") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImgCode()" src="' + value +'" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImgCode()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
        if (column.field == "authData") {
            if(value) {
                value=JSON.stringify(value);
                e.cellHtml = '<text>'+value+'</text>';
            }else{
                e.cellHtml = '';
            }
        }
    });

    function search() {
        var nickName = mini.get("nickName").getValue();
        var objectId = mini.get("objectId").getValue();
        var mobilePhoneNumber = mini.get("mobilePhoneNumber").getValue();
        var uid = mini.get("uid").getValue();
            grid.load({
                nickName: nickName,
                objectId:objectId,
                mobilePhoneNumber:mobilePhoneNumber,
                uid:uid,
            });
    }
    function searchObjectId() {
        var objectId = document.getElementById("objectId").value;
        grid.load({objectId:objectId})
    }
    function searchMobilePhoneNumber() {
        var mobilePhoneNumber = document.getElementById("mobilePhoneNumber").value;
        grid.load({mobilePhoneNumber:mobilePhoneNumber})
    }
    $("#nickName,#objectId,#mobilePhoneNumber").bind("keydown", function (e) {
        if (e.keyCode == 13) {
            search();
        }
    });


    // /////////////////////////////////////////////
    var Genders = [{ id: 1, text: '男' }, { id: 2, text: '女'}];
    function onGenderRenderer(e) {
        for (var i = 0, l = Genders.length; i < l; i++) {
            var g = Genders[i];
            if (g.id == e.value) return g.text;
        }
        return "";
    }
    function edit() {
        var row = grid.getSelected();
        if (row) {

            mini.open({
                url: "/getdata/edit?id="+row.objectId,
                title: "编辑用户信息", width: 700, height: 400,

//                onload: function () {
//                    var iframe = this.getIFrameEl();
//                    var data = { action: "edit", id: row.id };
//                    iframe.contentWindow.SetData(data);
//
//
//                },
                ondestroy: function (action) {

                    grid.reload();

                }
            });

        } else {
            alert("请选中一条记录");
        }

    }

    function bigImg() {
        var row = grid.getSelected();
        if (row) {
            if(flag==1) {
                var path = row.gender;
                $("#imgId").attr('src', path);
                $("#outImg").css('display','block');
            }
        }
    }
    function bigImgCode() {
        var row = grid.getSelected();
        if (row) {
            if(flag==1) {
                var path = row.qrCode;
                $("#imgId").attr('src', path);
                $("#outImg").css('display','block');
            }
        }
    }
    function smallImg() {
        $("#outImg").css('display','none');
    }
    function add() {

        mini.open({
            url: "/editor/add",
            title: "新增用户", width: 700, height: 400,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new"};
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                if(action=="save") {
                    grid.reload();
                }
            }
        });
    }

    function onBirthdayRenderer(e) {
        var value = e.value;
        if (value) return mini.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
        return "";
    }
    function onLiveRenderer(e) {
        var value = e.value;
        if (value==true||value==1) return (value, '可以直播');
        return "不能直播";
    }
    function onPhoneRenderer(e) {
        var value = e.value;
        if (value==true||value==1) return (value, '通过验证');
        return "未验证";
    }
    function onLoginRenderer(e) {
        var value = e.value;
        if (value==0) return (value, '不允许登陆');
        return "可以登录";
    }
    function onTypeRenderer(e) {
      var value = e.value;
      if (value==1) {
        return (value, 'VIP');
      } else if (value==2) {
        return (value, '合伙人');
      } else if (value==3) {
        return (value, '联创');
      } else if (value==4) {
        return (value, '总经理');
      } else if (value==0) {
        return (value, '普通会员');
      } else {
        return (value, '无等级');
      }

    }
    function redisRemove() {
        var row = grid.getSelected();
        if (row) {
            var objectId = row.objectId;
            $.ajax({
                url: "/getdata/usersInformation/cache/remove",
                type: 'post',
                data: {
                    objectId:objectId
                },
                success: function (result) {
                    if (result == 1){
                        alert('删除成功')
                        shopType = '';
                        grid.reload();
                    }else {
                        alert('删除失败，请重试！');
                        return;
                    }
                },
                error: function (error) {
                    console.log(error)
                }
            });

        } else {
            alert("请选中一条记录");
        }
    };
</script>
</html>
